﻿using CommunityToolkit.Mvvm.ComponentModel;
using CommunityToolkit.Mvvm.Input;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;

namespace BehaviorExtension
{
    /// <summary>
    /// Interaction logic for MainWindow.xaml
    /// </summary>
    public partial class MainWindow : Window
    {
        public MainWindow()
        {
            InitializeComponent();
            this.DataContext = new MainWindowViewModel();
        }
    }//end of class


    public partial class MainWindowViewModel : ObservableObject
    {
        public List<Student> Students { get; set; }

        [ObservableProperty]
        private int _selectedStudentId;

        public MainWindowViewModel()
        {
            Students = new List<Student>()
            {
                new Student() { Id = 1, Name = "张三", Age = 18 },
                new Student() { Id = 2, Name = "李四", Age = 19 },
                new Student() { Id = 3, Name = "王五", Age = 20 },
                new Student() { Id = 4, Name = "赵六", Age = 21 },
                new Student() { Id = 5, Name = "孙七", Age = 22 },
            };
        }

        [RelayCommand]
        private void SetSelectedStudentIdTo2()
        {
            SelectedStudentId = 2;
        }

    }//end of class

    public class Student
    {
        public int Id { get; set; }
        public string Name { get; set; }
        public int Age { get; set; }
    }
}